package cn.com.xjnt.vas.ordering.domain.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import cn.com.xjnt.vas.manage.domain.entity.Organization;

/**
 * The persistent class for the ordering_ward database table.
 * 
 */
@Entity
@Table(name = "ordering_ward")
@NamedQuery(name = "Ward.findAll", query = "SELECT w FROM Ward w")
public class Ward extends com.frameworks.core.entity.IdEntity {
    private static final long serialVersionUID = 1L;

    private String cardNo;

    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;

    private String name;
    private String remark;
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;

    // bi-directional many-to-one association to UserInfo
    @OneToMany(mappedBy = "ward")
    private List<UserInfo> userInfos;

    // bi-directional many-to-one association to Hospital
    @ManyToOne
    @JoinColumn(name = "hospital_id")
    private Hospital hospital;
    
    @ManyToOne
    @JoinColumn(name="organization_id")
    private Organization organization;
    public Ward() {
    }

    public String getCardNo() {
        return cardNo;
    }

    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }

    public Date getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getUpdateTime() {
        return this.updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public List<UserInfo> getUserInfos() {
        return this.userInfos;
    }

    public void setUserInfos(List<UserInfo> userInfos) {
        this.userInfos = userInfos;
    }

    public UserInfo addUserInfo(UserInfo userInfo) {
        getUserInfos().add(userInfo);
        userInfo.setWard(this);

        return userInfo;
    }

    public UserInfo removeUserInfo(UserInfo userInfo) {
        getUserInfos().remove(userInfo);
        userInfo.setWard(null);

        return userInfo;
    }

    public Hospital getHospital() {
        return hospital;
    }

    public void setHospital(Hospital hospital) {
        this.hospital = hospital;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    @PrePersist
    public void onCreate() {
        this.createTime = this.updateTime = new Date();
    }

    @PreUpdate
    public void onUpdate() {
        this.updateTime = new Date();
    }
}